home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / common.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-09  |  7.9 KB  |  235 lines

  1. /*
  2.  
  3.     File: common.h
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #define SECTOR_SIZE     0x200
  23.  
  24. #define MAX_CYLINDERS 65535
  25. #define MAX_HEADS 255
  26. #define MAX_SECTORS 63
  27.  
  28. #define DISKNAME_MAX    64
  29. #define DISKDESCRIPTION_MAX    128
  30. #define TAB_PART 0x1BE
  31. /* PARTITION TYPE */
  32. #define P_NO_OS         0x00
  33. #define P_12FAT         0x01
  34. #define P_16FAT         0x04
  35. #define P_EXTENDED      0x05
  36. #define P_16FATBD       0x06
  37. #define P_NTFS          0x07
  38. #define P_HPFS          0x07
  39. #define P_OS2MB         0x0A
  40. #define P_32FAT         0x0B
  41. #define P_32FAT_LBA     0x0C
  42. #define P_16FATBD_LBA   0x0E
  43. #define P_EXTENDX       0x0F
  44. #define P_LINUXEXTENDX  0x85
  45. #define P_12FATH        0x11
  46. #define P_16FATH        0x14
  47. #define P_16FATBDH      0x16
  48. #define P_NTFSH         0x17
  49. #define P_32FATH        0x1B
  50. #define P_32FAT_LBAH    0x1C
  51. #define P_16FATBD_LBAH  0x1E
  52. #define P_NETWARE    0x65
  53. #define P_OLDLINUX      0x81
  54. #define P_LINSWAP       0x82
  55. #define P_LINUX         0x83
  56. #define P_LVM        0x8E
  57. #define P_FREEBSD       0xA5
  58. #define P_OPENBSD       0xA6
  59. #define P_NETBSD        0xA9
  60. #define P_BEOS          0xEB
  61. #define P_RAID        0xFD
  62. enum upart_type { UP_UNK, UP_FAT12, UP_FAT16, UP_FAT32, UP_EXTENDED, UP_NTFS, UP_HPFS, UP_OS2MB, UP_NETWARE, UP_EXT2, UP_EXT3, UP_LVM, UP_FREEBSD, UP_OPENBSD, UP_BEOS, UP_RAID, UP_LINSWAP, UP_LINSWAP2, UP_RFS, UP_RFS2 };
  63. typedef enum upart_type upart_type_t;
  64. enum status_type { STATUS_DELETED, STATUS_PRIM, STATUS_PRIM_BOOT, STATUS_LOG, STATUS_EXT, STATUS_EXT_IN_EXT};
  65. typedef enum status_type status_type_t;
  66. enum errcode_type {BAD_NOERR, BAD_SS, BAD_ES, BAD_SH, BAD_EH, BAD_EBS, BAD_RS, BAD_SC, BAD_EC, BAD_SCOUNT};
  67. typedef enum errcode_type errcode_type_t;
  68. enum aff_part_type {AFF_PART_NONL, AFF_PART_NL, AFF_PART_ORDER, AFF_PART_SHORT};
  69. typedef enum aff_part_type aff_part_type_t;
  70. int wdoprintf(WINDOW *window, const char *_format, ...) __attribute__ ((format (printf, 2, 3)));
  71. int ecrit_rapport(const char *_format, ...) __attribute__ ((format (printf, 1, 2)));
  72. void ecrit_rapport_string(const char *string,const int max_length);
  73.  
  74. typedef struct cellule_disk_param t_param_disk;
  75.  
  76. typedef unsigned char t_sector[0x200];
  77. typedef unsigned char t_entry[0x10];
  78. typedef struct cellule_diskext t_diskext;
  79. typedef struct cellule_CHS t_CHS;
  80. #define pt_offset_const(b, n) ((const struct partition_dos *)((b) + 0x1be + \
  81.       (n) * sizeof(struct partition_dos)))
  82. #define pt_offset(b, n) ((struct partition_dos *)((b) + 0x1be + \
  83.       (n) * sizeof(struct partition_dos)))
  84.  
  85. struct partition_dos {
  86.     unsigned char boot_ind;         /* 0x80 - active */
  87.     unsigned char head;             /* starting head */
  88.     unsigned char sector;           /* starting sector */
  89.     unsigned char cyl;              /* starting cylinder */
  90.     unsigned char sys_ind;          /* What partition type */
  91.     unsigned char end_head;         /* end head */
  92.     unsigned char end_sector;       /* end sector */
  93.     unsigned char end_cyl;          /* end cylinder */
  94.     unsigned char start4[4];        /* starting sector counting from 0 */
  95.     unsigned char size4[4];         /* nr of sectors in partition */
  96. };
  97.  
  98. struct cellule_CHS
  99. {
  100.   unsigned int cylinder;
  101.   unsigned int head;
  102.   unsigned int sector;
  103. };
  104.  
  105. typedef struct cellule_list_part t_list_part;
  106. struct cellule_list_part
  107. {
  108.   t_diskext *part;
  109.   t_list_part *prev;
  110.   t_list_part *next;
  111.   int to_be_removed;
  112. };
  113.  
  114. typedef struct cellule_list_disk t_list_disk;
  115. struct cellule_list_disk
  116. {
  117.   t_param_disk *disk;
  118.   t_list_disk *prev;
  119.   t_list_disk *next;
  120. };
  121.  
  122. struct cellule_disk_param
  123. {
  124.   dword size;
  125.   t_CHS CHS;    /* logical CHS */
  126.   int halt_on_errors;
  127.   int write_used;
  128.   char description_txt[DISKDESCRIPTION_MAX];
  129.   char *(*description)(t_param_disk *disk_car);
  130.   int (*read)(t_param_disk *disk_car,const unsigned int nbr_sector, void *nom_buffer, const dword pos);
  131.   int (*write)(t_param_disk *disk_car,const unsigned int nbr_sector, const void *nom_buffer, const dword pos);
  132.   int (*clean)(t_param_disk *disk_car);
  133.   void *data;
  134. };
  135.  
  136. struct cellule_diskext
  137.  {
  138.   dword lba;
  139.   dword part_size;
  140.   dword boot_sector;
  141.   dword blocksize;
  142.   unsigned char part_type;
  143.   upart_type_t upart_type;
  144.   status_type_t status;
  145.   unsigned int order;
  146.   errcode_type_t errcode;
  147.   char name[80];
  148.   char info[80];
  149.  };
  150.  
  151. typedef struct str_fat t_fat_test;
  152. struct str_fat
  153. {
  154.   dword offset;
  155.   int f_fat12;
  156.   int f_fat16;
  157.   int f_fat32;
  158. };
  159. typedef struct struct_my_data t_my_data;
  160. struct struct_my_data
  161. {
  162.   t_param_disk *disk_car;
  163.   t_diskext *partition;
  164.   __s64 offset;
  165. };
  166.  
  167. void dup_t_diskext(t_diskext *dest, const t_diskext *src);
  168. int ask_YN(WINDOW *window,const char*msg);
  169. int read_line(void);
  170. char read_char(const char *);
  171. void *MALLOC(size_t size);
  172. void FREE(void *ptr);
  173. char read_key(void);
  174. char test_key(void);
  175. unsigned int up2power(const unsigned int number);
  176. void hd_parse_bis(const t_list_disk * list_disk, const int allow_partial_last_cylinder);
  177. t_list_disk *hd_parse(t_list_disk *list_disk,const int debug);
  178. t_param_disk *file_test_availability(const char *device, const int debug);
  179. void my_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
  180. int check_volume_name(const char *name,const unsigned int max_size);
  181. void set_part_name(t_diskext *partition,const char *src,const int max_size);
  182. int rebuild_FAT_BS(t_param_disk *disk_car,t_diskext *partition, const int debug, const int dump_ind,const int interface);
  183. int rebuild_NTFS_BS(t_param_disk *disk_car,t_diskext *partition, const int debug, const int dump_ind,const int interface);
  184. #ifndef BSD_MAXPARTITIONS
  185. #define    BSD_MAXPARTITIONS    8
  186. #endif
  187. #ifndef OPENBSD_MAXPARTITIONS
  188. #define    OPENBSD_MAXPARTITIONS    16
  189. #endif
  190.  
  191. #if defined(__i386__) || defined(__alpha__)
  192. #define le16(x)  (x)             /* x as little endian */
  193. #define be16(x)  ((((x)&0xff00)>>8)                      | \
  194.     (((x)&0x00ff)<<8))
  195. #define le32(x)  (x)
  196. #define be32(x)  ((((x)&0xff000000L)>>24)                | \
  197.     (((x)&0x00ff0000L)>>8)                  | \
  198.     (((x)&0x0000ff00L)<<8)                  | \
  199.     (((x)&0x000000ffL)<<24))
  200. #define le64(x)  (x)
  201. #define be64(x)  ((((x)&0xff00000000000000LL)>>56)       | \
  202.     (((x)&0x00ff000000000000LL)>>40)        | \
  203.     (((x)&0x0000ff0000000000LL)>>24)        | \
  204.     (((x)&0x000000ff00000000LL)>>8)         | \
  205.     (((x)&0x00000000ff000000LL)<<8)         | \
  206.     (((x)&0x0000000000ff0000LL)<<24)        | \
  207.     (((x)&0x000000000000ff00LL)<<40)        | \
  208.     (((x)&0x00000000000000ffLL)<<56))
  209. #else /* bigendian */
  210. #define le16(x)  ((((x)&0xff00)>>8)                      | \
  211.     (((x)&0x00ff)<<8))
  212. #define be16(x)  (x)
  213. #define le32(x)  ((((x)&0xff000000L)>>24)                | \
  214.     (((x)&0x00ff0000L)>>8)                  | \
  215.     (((x)&0x0000ff00L)<<8)                  | \
  216.     (((x)&0x000000ffL)<<24))
  217. #define be32(x)  (x)
  218. #define le64(x)  ((((x)&0xff00000000000000LL)>>56)       | \
  219.     (((x)&0x00ff000000000000LL)>>40)        | \
  220.     (((x)&0x0000ff0000000000LL)>>24)        | \
  221.     (((x)&0x000000ff00000000LL)>>8)         | \
  222.     (((x)&0x00000000ff000000LL)<<8)         | \
  223.     (((x)&0x0000000000ff0000LL)<<24)        | \
  224.     (((x)&0x000000000000ff00LL)<<40)        | \
  225.     (((x)&0x00000000000000ffLL)<<56))
  226. #define be64(x)  (x)
  227. #endif
  228. #ifndef HAVE_SNPRINTF
  229. int snprintf(char *str, size_t size, const char *format, ...);
  230. #endif
  231. #ifndef HAVE_VSNPRINTF
  232. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  233. #endif
  234.  
  235.